<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20">
			<u-search placeholder="请输入关键词搜索" :clearabled="true" v-model="keyword" border-color="#606266" @custom="search" @search="search"></u-search>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="9" text-align="left">
							<view class="weikaishi2 lanse">
								<span>运单号：{{item.dispatchNumber}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right">
							<view class="u-line-1 weikaishi2">
								<span>{{item.tstate}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="5" text-align="center">
							<view class="u-line-1">
								<u-icon name="car-fill" :label="item.carnumbger" label-size="33" label-color="#19be6b" color="#19be6b" size="45"></u-icon>
							</view>
						</u-col>
						<u-col span="4" text-align="center">
							<view class="u-line-1 u-m-t-5">
								<span>{{item.privatecarType}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center">
							<view class="u-line-1 u-m-t-5" @click="badaphone(item.cartel)">
								<u-icon name="phone" :label="item.driver1" label-color="#2b85e4" color="#2b85e4" size="35"></u-icon>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<view class="u-line-1 weikaishi4">
								<span>调度时间：{{item.createTime}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-2 weikaishi4">
								<span>体积：{{item.tooDeployVolume}}m³</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-2 weikaishi4">
								<span>件数：{{item.tooDeployNum}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="center">
							<view class="u-line-1 weikaishi4">
								<span>参考价:{{item.consultMoney}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="center">
							<view class="u-line-1 weikaishi4">
								<span>运费:{{item.freightMoney}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="center">
							<view class="u-line-1 u-m-t-2">
								<u-line-progress active-color="#19be6b" :striped="true" :percent="(item.tooDeployVolume/item.privatecarSurevolume*100).toFixed(1)" :striped-active="true"></u-line-progress>
							</view>
						</u-col>
					</u-row>
					<view v-for="(item1,index1) in item.list" :key="index1">
						<u-row>
							<u-col span="9" text-align="left">
								<view class=" u-m-t-2 weikaishi4">
									<span>{{item1.getUnit}}</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center">
								<view class="u-line-1 u-m-t-5" @click="badaphone(item1.getTel)">
									<u-icon name="phone" :label="item1.getPeople" label-color="#2b85e4" color="#2b85e4" size="30"></u-icon>
								</view>
							</u-col>
							<u-col span="12" text-align="left">
								<view class=" u-m-t-2 weikaishi5">
									<span><u-icon name="map" size="29" labelSize="14px" labelColor="#00c300" label="地址"></u-icon>：{{item1.getLocation}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="weikaishi4">
									<span>线路：{{item1.lineName}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="weikaishi4">
									<span>公里数：{{item1.kilometer}}</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-2">
									<span>体积{{item1.tooVolume}}m³</span>
								</view>
							</u-col>
							<u-col span="6" text-align="left">
								<view class="u-line-1 u-m-t-2">
									<span>数量{{item1.totalNum}}</span>
								</view>
							</u-col>
							<u-col span="12" text-align="right" >
								<view class="u-m-t-25 u-line-1">
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</view>
			<view class="foot-butten" slot="foot">
				<view :class="flex">
					<u-col span="4" text-align="center" @click="tooCarsy(item.dispatchNumber)">
						<view  class="u-m-10 u-border-right">
							配置详情
						</view>
					</u-col>
					<u-col span="4" text-align="center" @click="tofeiyong(item.dispatchNumber)">
						<view  class="u-m-10 u-border-right">
							费用信息
						</view>
					</u-col>
					<u-col span="4" text-align="center" @click="examine(item)">
						<view  class="u-m-10 ">
							审核
						</view>
					</u-col>
				</view>
			</view>
		</u-card>
		<u-popup v-model="show3" mode="center" closeable width="650rpx" height="850rpx" border-radius="10">
			<view class="u-text-left u-m-t-20 weikaishi2 lanse" style="margin-left: 20rpx;">线路费用报价</view>
			<view class="wrap">
				<view style="background-color: #eaeaea;" v-for="item in feiyonglist" :key="item.id">
					<u-row>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-10 weikaishi3">
								<span>{{item.priceName}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<view class="u-line-1">
								<span>线路：{{item.lineName}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1">
								<span>单价：{{item.price}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1">
								<span>计价方式：{{item.priceMode}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-10">
								<span>总量：{{item.nums}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-10 lanse">
								<span>金额：{{item.money}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="show4" mode="center" closeable width="500rpx" height="300rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">定价审核</view>
			<view class=" u-m-20">
				<u-input v-model="examineNodes" type="text" border="true" placeholder="请输入审核内容"/>
			</view>
			<view  style="height: 80rpx">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="bohui()">驳回</u-button>
					<u-button size="medium" type="primary" @click="tongguo()">通过</u-button>
				</view>
			</view>
		</u-popup>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	import bmap from '../../static/js/bmap-wx.js'
	import config from '../../config.js'
	export default {
		data() {
			return {
				flex:'',
				dataList: [],
				show3:false,
				feiyonglist:[],
				keyword:"",
				show4:false,
				edititem:'',
				examineNodes:'',
				
				BMap:{},
			}
		},
		onLoad() {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			uni.showLoading({
				title: '加载中'
			})
			this.refresh()
			setTimeout(() => {
				uni.hideLoading()
			}, 500)
			
			// 新建百度地图对象 
			//#ifdef MP-WEIXIN
			this.BMap = new bmap.BMapWX({ 
				ak: 'ESWpVgDaBgDk7KWsgkUkBE6kzAN0BKTa' 
			});
			//#endif
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			})
			this.refresh()
			setTimeout(() => {
				uni.hideLoading()
				uni.stopPullDownRefresh()
			}, 500)
		},
		methods: {
			search(e){
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
			tongguo(){
				uni.showLoading({
					title: '正在提交'
				})
				this.$http.post('/rest/transport/tongguo',{
				},{
					params:{
						examineNodes: this.examineNodes,
						dispatchNumber: this.edititem.dispatchNumber
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if(res.data.success) {
						this.$refs.uToast.show({
							title: '操作成功'+res.data.message,
							type: 'success'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
						this.show4 = false
						
						//#ifdef MP-WEIXIN
						var that = this
						
						// if(this.edititem.list[0].setLocation != null && this.edititem.list[0].setLocation != ''){
						// 	if(this.edititem.list[0].longitude == null || this.edititem.list[0].longitude == '' || this.edititem.list[0].longitude == 0 || this.edititem.list[0].latitude == null || this.edititem.list[0].latitude == '' || this.edititem.list[0].latitude == 0){
						// 		this.BMap.geocoding({
						// 			address: that.edititem.list[0].setLocation, 
						// 			fail: function (res) {
						// 				//地址转经纬度失败
						// 			},
						// 			success: function (res) {
						// 				//更新装货地址 经纬度
						// 				uni.request({
						// 					method:"POST",
						// 					url: config.root +'/rest/transport/editAddress?id='+that.edititem.list[0].setLocationId+'&longitude='+res.wxMarkerData[0].longitude+'&latitude='+res.wxMarkerData[0].latitude,
						// 					data:{
						// 					},
						// 					header:{
						// 						'Authorization' :uni.getStorageSync('token'),
						// 					},
						// 					success: (res) => {
						// 						if(res.data.code == 200){
						// 							//成功更新
						// 							console.log('成功更新发货地址信息')
						// 						} 
						// 					}
						// 				})
						// 			}
						// 		}); 
						// 	}
						// }
						
						let switchWl = false
						for(let item1 of that.edititem.list){
							if(item1.getLocation != null && item1.getLocation != ''){
								this.$http.post('/rest/address/getByid',{
								},{
									params: {
										id:item1.getLocationId
									},
									header: {
										'Authorization' :uni.getStorageSync('token'),
									}
								}).then(res => {
									if(res.data.data.switchWl == 1){
										console.log('收货地址围栏为开启')
										if(switchWl == false){
											console.log('创建轨迹实例')
											uni.request({
												method:"POST",
												url: 'https://yingyan.baidu.com/api/v3/entity/add',
												data:{
													ak: 'wYkHbMlxX7unRpCiRO3LzAr6DSVrdcGK',
													service_id: 229331,
													entity_name: this.edititem.carnumbger+'-'+this.edititem.dispatchNumber,
													entity_desc: this.edititem.carnumbger+'在途监控'
												},
												header:{
													'Content-Type':'application/x-www-form-urlencoded'
												},
												success: (res) => {
													if(res.data.status == 0){
														uni.request({
															method:"POST",
															url: config.root +'/rest/transport/edittDispatch?dispatchNumber='+this.edititem.dispatchNumber,
															data:{
															},
															header:{
																'Authorization' :uni.getStorageSync('token'),
															},
															success: (res) => {
																if(res.data.code == 200){
																	//成功更新
																	switchWl = true
																} 
															}
														})
													} else {
														//创建轨迹实例失败
													}
												}
											})
										}
									}
									// if(item1.longitude2 == null || item1.longitude2 == '' || item1.longitude2 == 0 || item1.latitude2 == null || item1.latitude2 == '' || item1.latitude2 == 0){
									// 	this.BMap.geocoding({
									// 		address: item1.getLocation, 
									// 		fail: function (res) {
									// 			//地址转经纬度失败
									// 		},
									// 		success: function (res) {
									// 			//更新卸货地址 经纬度
									// 			uni.request({
									// 				method:"POST",
									// 				url: config.root +'/rest/transport/editAddress?id='+item1.getLocationId+'&longitude='+res.wxMarkerData[0].longitude+'&latitude='+res.wxMarkerData[0].latitude,
									// 				data:{
									// 				},
									// 				header:{
									// 					'Authorization' :uni.getStorageSync('token'),
									// 				},
									// 				success: (res) => {
									// 					if(res.data.code == 200){
									// 						//成功更新
									// 						console.log('成功更新收货地址信息')
									// 					} 
									// 				}
									// 			})
									// 		}
									// 	}); 
									// }
								})
							}
						}
						//#endif
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
					}
				})
			},
			bohui(){
				if(typeof this.examineNodes == 'undefined' || this.examineNodes == null || this.examineNodes == ""){
					uni.showToast({
						title: "请输入审核内容",
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '正在提交'
				})
				this.$http.post('/rest/transport/bohui',{
				},{
					params:{
						examineNodes: this.examineNodes,
						dispatchNumber: this.edititem.dispatchNumber
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if(res.data.code == 200) {
						this.$refs.uToast.show({
							title: '驳回成功',
							type: 'success'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
						this.show4 = false
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
					}
				})
			},
			examine(item){
				this.edititem = item
				this.show4 = true
			},
			tofeiyong(dispatchNumber){
				this.$http.post('/rest/transportCar/cost',{
				},{
					params: {
						dispatchNumber:dispatchNumber
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.feiyonglist = res.data.data
					this.show3 = true
				})
			},
			refresh(){
				this.$http.post('/rest/transportCar/findCarListBySpecToo2',{
				},{
					params: {
						keyword:this.keyword,
						findtype:'3'
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
				})
			},
			badaphone(tel){
				if(tel == null || tel == ''){
					uni.showToast({
						title: "暂无联系电话",
						icon: 'none'
					})
				} else {
					uni.makePhoneCall({
					    phoneNumber: tel
					});
				}
			},
			tooCarsy(dispatchNumber){
				this.$Router.push({
					name: 'checktooy',
					params: { dispatchNumber:dispatchNumber}
				})
			},
			sectionChange(e){
				this.current = e
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
		}
	}
</script>


<style lang="scss">
	.u-body-item {
		padding: 20rpx 15rpx;
	}
	.wrap {
		padding: 0rpx 12rpx;
	}

	.u-row {
		margin: 10rpx 2rpx;
	}
	.weikaishi2{
		font-size: 34rpx;
	}
	.weikaishi3{
		font-size: 30rpx;
	}
</style>
